package org.lanqiao.controller;


import org.lanqiao.dao.WxuserDao;
import org.lanqiao.entity.Wxuser;
import org.lanqiao.service.WxuserService;
import org.lanqiao.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ResponseBody
@RequestMapping("/wxuser")
public class WxuserController {

    @Autowired
    WxuserService wxuserService;

    @Autowired
    WxuserDao wxuserDao;



    /**
     * @Author 王宇
     * @Description //TODO 查询单个用户
     * @Date 2019/06/11 9:30
     * @Param [wxId]
     * @return org.lanqiao.entity.Wxuser
     */
    @ResponseBody
    @RequestMapping("/getWxUser")
    public Result getWxUser(String wxId){
        return wxuserService.getWxUser(wxId);
    }





/**
     * @Author 徐金星
     * @Description //TODO
     * @Date 2019/6/12 19:03
     * @Param [nickname, chathead, openid]
     * @explain
     * @return org.lanqiao.util.Result
     */
    @RequestMapping("/addWxUser")
    public Result addWxUser(Wxuser wxuser){
        Wxuser wxUser = wxuserDao.getWxUser(wxuser.getWxId());
        if (wxUser!=null){
            return wxuserService.getWxUser(wxUser.getWxId());
        }else{
        wxuser.setWxStatus(0);
        wxuser.setWxBalance(0.00);
        return wxuserService.addWxUser(wxuser);
        }
    }


}
